//
//  SWChildrenFetchReq.swift
//  ChildStory
//
//  Created by linhan on 16/9/1.
//  Copyright © 2016年 Aiya. All rights reserved.
//

import Foundation
class SWChildrenFetchReq: SWBaseRequest
{
    override init()
    {
        super.init()
        api = SWRequestAPI.ChildrenFetch
    }
    
    override func JSONToModel(_ json:JSON, JSONString:String, JSONData:Data) -> AnyObject?
    {
        return Mapper<SWChildrenFetchRsp>().map(JSONString: JSONString)
    }
}

class SWChildrenFetchRsp: NSObject,Mappable
{
    var code:Int?
    var children:[SWChildRsp]?
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        code        <- map["code"]
        children    <- map["data.babies"]
    }
}

class SWChildRsp: NSObject,Mappable
{
    var uid:Int? = 1
    var screenName:String?
    var infantName:String?
    var gender:Int?
    var avatar:String?
    var birthday:Date?
    
    required init?(map: Map) { }
    
    // Mappable
    func mapping(map: Map) {
        let formatter:DateFormatter = DateFormatter()
        formatter.dateFormat = "YYYY-MM-dd HH-mm-ss"
        uid            <- map["id"]
        screenName     <- map["nickName"]
        infantName     <- map["infant_name"]
        avatar         <- map["avatar"]
        gender         <- map["gender"]
        birthday       <- (map["birthdayStr"], DateFormatterTransform(dateFormatter: formatter))
    }
}
